package com.shire.movienizerdroid.activity;

import java.io.File;

import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

import com.shire.movienizerdroid.R;

/**
 * @author yhernandezdiaz
 */
public class MDPreferenceActivity extends PreferenceActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.addPreferencesFromResource(R.xml.preferences);
	}

	public static boolean isDownloadingPicturesAllowed(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("allow_downloading_pictures", false);
	}

	public static String getDatabasePath(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context).getString("database_path", null);
	}

	public static void setDatabasePath(Context context, String path) {
		PreferenceManager.getDefaultSharedPreferences(context).edit().putString("database_path", path).commit();
	}

	public static String getDatabaseParentPath(Context context) {
		final File dbPath = new File(PreferenceManager.getDefaultSharedPreferences(context).getString("database_path", null));
		if (dbPath.exists())
			return dbPath.getParent();
		else
			return null;
	}

}
